﻿#region Creditos

/* Autor: Edilberto Sánchez Forero	*/
/* Email: esanchezfo@gmail.com		*/
/* Licencia: LGPL, Software Libre	*/
/* País: Colombia, Bogotá			*/

#endregion

#region Librerias

using System.Collections.Generic;
using System.Net;
using Ciatel.ISO8583.Amex;
using Ciatel.ISO8583.Amex.Utilities;
using ESF.General;
using ESF.SSO.Core.Entities;
using ESF.SSO.Core.Entities.BasicReferences;
using ESF.General.Entity;
using System.Net.Sockets;

#endregion


namespace ESF.SSO.ISO8583.ClientRequestHandler.Operations
{
	internal static class GetList_I
	{
		internal static void ProcessRequest (List<Message> pRequests, IPEndPoint pSenderIPEndPoint, IPEndPoint pForwarderIPEndPoint, out List<object> pProcessedObjects)
		{
			Message message;
			
			List<BasicReference> list;
			
			CustomField cf_57;
			
			int listItemCount;
			
			
			message = pRequests [0];
			
			
			pProcessedObjects = new List<object> ();
			
			if (message.ApplicationData.DataElements.IsFieldFullFilled (TheKnownFields.CustomPrivateField_57))
			{
				list = new List<BasicReference> ();
				
				foreach (Message msg in pRequests)
				{
					cf_57 = msg.ApplicationData.DataElements.GetCustomPrivateField_57 ();
					
					listItemCount = (int) cf_57.GetNumericFieldAsLong (4);	// N 4
				
					// No utilizado (indice)
					cf_57.GetNumericFieldAsLong (4);	// N 4
				
					for (int j = 0; j < 12 && listItemCount > 0; j++, listItemCount --)
					{
						list.Add (
							new BasicReference ()
							{
								Code = cf_57.GetStringFieldWithVariableLength (60), // Ans .. 60
								Name = cf_57.GetStringFieldWithVariableLength (60),  // Ans .. 60								
							});
					}
				}
				
				pProcessedObjects.Add (list);
			}
			else
			{
				pProcessedObjects.Add (null);
			}
		}
	}
}
